#include "conn_manager.hpp"
#include "datagram.hpp"
#include "datagram_factory.hpp"
#include "processor.hpp"

using namespace tcp;

ConnManager * g_conn_manager = NULL;
Processor   * g_processor    = NULL;

bool init()
{
	FixedSizeAllocator * fsa = new FixedSizeAllocator(4096, 10);

	g_conn_manager  = new ConnManager(1024, fsa);

	DatagramFactory * factory = new DatagramFactory;

	g_processor = new Processor;
	g_conn_manager->add_connector("127.0.0.1", 12345, factory, g_processor);

	return true;
}

int main(int argc, char * argv[])
{
	init();

	int flag = 0;

	while (true)
	{
		g_conn_manager->poll();

		if (0 == flag)
		{
			flag = 1;
			
			DatagramTest1Req req;

			req._data  = "Hello World";

			g_processor->send_datagram(req);
		}
	}

	return 0;
}

